/*******************************************************************************
 * @project: ServletTest
 * @package: com.burns.servlet
 * @file: HelloWorld.java
 * @author: Administrator
 * @created: 2017-5-16
 * @purpose:
 * 
 * @version: 1.0
 * 
 * Revision History at the end of file.
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/

package com.burns.servlet;

//导入必需的 java 库
import java.io.*;
import java.net.URL;
import java.net.URLConnection;

import javax.servlet.*;
import javax.servlet.http.*;

//扩展 HttpServlet 类
public class HelloWorld extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String message;

	public void init() throws ServletException {
		// 执行必需的初始化
		message = "Hello World";
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		String urlStr = "http://api.csdn.net/oauth2/authorize?client_id=1100309&redirect_uri=http://localhost:8080/ServletTest/GetCode&response_type=code";
		// String urlStr =
		// "http://api.csdn.net/oauth2/access_token?client_id=1100309&client_secret=23eaf6637b2d43128c518b8d7e4078ac&grant_type=authorization_code &redirect_uri=http://localhost:8080/zckf/login.html&code=52cc18a67e5e4382a1a0c242cf45c307";

		// 链接URL
		// URL url = new URL(urlStr);
		// 返回结果集
		// StringBuffer document = new StringBuffer();
		// 创建链接
		// URLConnection conn = url.openConnection();
		// // 读取返回结果集
		// BufferedReader reader = new BufferedReader(new InputStreamReader(
		// conn.getInputStream(), "utf-8"));
		// String line = null;
		// while ((line = reader.readLine()) != null) {
		// document.append(line);
		// }

		// 设置响应内容类型
		response.setHeader("content-type", "text/html;charset=UTF-8");

		// 实际的逻辑是在这里
		PrintWriter out = response.getWriter();
		out.println("<h1>" + message + "</h1>");
		out.println("<ol>");
		out.println("<li><a href='" + urlStr + "'>getcode</a></li><br>");

		// get方法获取参数：
		String getUrl = "http://localhost:8080/ServletTest/HelloForm?first_name=ZARA&last_name=ALI";
		out.println("<li><a href='" + getUrl + "'>get方法获取参数</a></li><br>");

		String getOrPost = "http://localhost:8080/ServletTest/hello.html";
		out.println("<li><a href='" + getOrPost
				+ "'>get或post的使用方法</a></li><br>");

		String displayHeaderUrl = "http://localhost:8080/ServletTest/DisplayHeader";
		out.println("<li><a href='" + displayHeaderUrl
				+ "'>HTTP Header 请求实例</a></li>");
		

		String refreshUrl = "http://localhost:8080/ServletTest/Refresh";
		out.println("<li><a href='" + refreshUrl
				+ "'>自动刷新 Header 设置</a></li>");
		
		String showErrorUrl = "http://localhost:8080/ServletTest/ShowError";
		out.println("<li><a href='" + showErrorUrl
				+ "'>把 407 错误代码发送到客户端浏览器</a></li>");
		
		String readCookiesUrl = "http://localhost:8080/ServletTest/ReadCookies";
		out.println("<li><a href='" + readCookiesUrl
				+ "'>读取上面的实例中设置的 Cookies</a></li>");
		
		String deleteCookiesUrl = "http://localhost:8080/ServletTest/DeleteCookies";
		out.println("<li><a href='" + deleteCookiesUrl
				+ "'>删除现有的名为 first_name的 cookie</a></li>");
		
		
		out.println("</ol>");
	}

	public void destroy() {
		// 什么也不做
	}
}

/*******************************************************************************
 * <B>Revision History</B><BR>
 * [type 'revision' and press Alt + / to insert revision block]<BR>
 * 
 * 
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/
